@@ -1,6 +1,6 @@ |
||
| 1 | 1 |
{
|
| 2 | 2 |
"name": "hubot-multi-adapter", |
| 3 |
- "version": "0.3.4", |
|
| 3 |
+ "version": "0.3.5", |
|
| 4 | 4 |
"description": "A Hubot adapter that can receive messages thru socket.io or telegram", |
| 5 | 5 |
"main": "src/multi-adapter", |
| 6 | 6 |
"scripts": {
|
@@ -27,20 +27,22 @@ curl -XPOST https://api.telegram.org/botXXXX/deleteWebhook |
||
| 27 | 27 |
curl -XPOST https://api.telegram.org/botXXXX/setWebhook?url=https://example.com/api/telegram |
| 28 | 28 |
``` |
| 29 | 29 |
|
| 30 |
+More info on *Telegram Bots* can be found [**here**](https://core.telegram.org/bots). |
|
| 31 |
+ |
|
| 30 | 32 |
### Webhooks |
| 31 | 33 |
|
| 32 | 34 |
You can send **webhooks** thru this adapter using the endpoint ```/webhook```. Make sure your request has a body with the user object: |
| 33 | 35 |
|
| 34 | 36 |
``` |
| 35 |
-"user" : {
|
|
| 36 |
- "first_name" : "John", |
|
| 37 |
- "last_name" : "Doe", |
|
| 38 |
- "room" : 455098, |
|
| 39 |
- "username" : "jamesperet" |
|
| 40 |
- "service" : "telegram", |
|
| 41 |
- "command" : "example-command" |
|
| 42 |
- "msg_type" : "command" |
|
| 37 |
+{
|
|
| 38 |
+ "user": {
|
|
| 39 |
+ "first_name": "John", |
|
| 40 |
+ "last_name": "Doe", |
|
| 41 |
+ "room": 238947239874238947, |
|
| 42 |
+ "username": "johndoe", |
|
| 43 |
+ "service": "telegram", |
|
| 44 |
+ "msg_type": "command" |
|
| 45 |
+ }, |
|
| 46 |
+ "text": "example-command" |
|
| 43 | 47 |
} |
| 44 | 48 |
``` |
| 45 |
- |
|
| 46 |
-More info on *Telegram Bots* can be found [**here**](https://core.telegram.org/bots). |
@@ -88,23 +88,22 @@ class MultiAdapter extends Adapter |
||
| 88 | 88 |
app.post '/webhook', (req, res) => |
| 89 | 89 |
console.log(req.body) |
| 90 | 90 |
if req.body.user != undefined |
| 91 |
- if req.body.user.room && req.body.user.service && req.body.user.first_name && req.body.user.last_name && req.body.user.username && req.body.user.msg_type |
|
| 91 |
+ if req.body.text && req.body.user.room && req.body.user.service && req.body.user.first_name && req.body.user.last_name && req.body.user.username && req.body.user.msg_type |
|
| 92 | 92 |
chat_id = req.body.user.room |
| 93 | 93 |
# Get username |
| 94 | 94 |
user_name = req.body.user.first_name + " " + req.body.user.last_name |
| 95 |
- command = req.body.command |
|
| 95 |
+ text = req.body.text |
|
| 96 | 96 |
@robot.brain.set 'log_id_' + chat_id, new Date().getUTCMilliseconds() |
| 97 | 97 |
user = @userForId chat_id, name: user_name, room: chat_id |
| 98 | 98 |
console.log("Webhook received from " + user_name + " with command:" )
|
| 99 |
- console.log(command) |
|
| 99 |
+ console.log(text) |
|
| 100 | 100 |
user.service = req.body.user.service |
| 101 | 101 |
user.first_name = req.body.user.first_name |
| 102 | 102 |
user.last_name = req.body.user.last_name |
| 103 | 103 |
user.username = req.body.user.username |
| 104 |
- user.command = command |
|
| 105 | 104 |
user.room = chat_id |
| 106 | 105 |
user.msg_type = req.body.user.msg_type |
| 107 |
- @receive new TextMessage user, command |
|
| 106 |
+ @receive new TextMessage user, text |
|
| 108 | 107 |
res.status(400).send({"message" : "received"})
|
| 109 | 108 |
else |
| 110 | 109 |
res.status(400).send({"message" : "The user object has mising properties. Follow instruction on https://github.com/jamesperet/hubot-multi-adaptor"})
|